package com.ui;

import javax.swing.*;
import java.awt.event.*;

public class Pac_usrchongzhi extends JDialog {
    private JPanel contentPane;
    private JButton buttonOK;
    private JButton buttonCancel;
    private JTextField textField1;
    private JTextField textField2;
    private JTextField textField3;
    private JButton Button1;
    private JTextArea textArea1;

    public JTextArea getTextArea(String str) {
//        textArea1.append("开始认证\n");
        textArea1.append(str);
        //textArea.append("sadsad55\n");
        return textArea1;
    }
    public Pac_usrchongzhi() {
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);

        buttonOK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onOK();
            }
        });

        buttonCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        });

        // 点击 X 时调用 onCancel()
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

        // 遇到 ESCAPE 时调用 onCancel()
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        Button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                onInitial();
            }
        });
    }
    private void onInitial(){
        textField3.setText(String.valueOf(DENGLU.c.getCharge()));
    }
    private void onOK() {
        // 在此处添加您的代码
        String STR=textField2.getText();
        DENGLU.c.process(DENGLU.c.Charge(Integer.parseInt(textField1.getText())));
        JTextArea textArea1=getTextArea("发送给V的报文:"+DENGLU.c.pk+"\n");
        textArea1=getTextArea("数字签名:\n"+DENGLU.c.key_dv+"\n");
        textArea1=getTextArea("解密后的明文:"+DENGLU.c.p+"\n");

    }

    private void onCancel() {
        // 必要时在此处添加您的代码
        dispose();
    }

    public void main() {
        Pac_usrchongzhi dialog = new Pac_usrchongzhi();
        dialog.pack();
        dialog.setVisible(true);
    }
}
